package com.huzz.util.exception;

import com.huzz.util.body.ResultCode;

/**
 * 业务异常处理
 */
public class BizException extends RuntimeException {

    private static final long serialVersionUID = 1L;

    /**
     * 错误码
     */
    protected int statusCode;

    /**
     * 错误信息
     */
    private String errorMessage;

    public BizException() {
        super();
    }

    public BizException(ResultCode resultCode) {
        super(resultCode.getMessage());
        this.statusCode = resultCode.getCode();
        this.errorMessage = resultCode.getMessage();
    }

    public BizException(ResultCode resultCode, Throwable cause) {
        super(resultCode.getMessage(), cause);
        this.statusCode = resultCode.getCode();
        this.errorMessage = resultCode.getMessage();
    }

    public BizException(int statusCode, String msg) {
        super(msg);
        String c = msg.substring(msg.length() - 1);
        if (!".".equals(c) && !"。".equals(c) && !" ".equals(c)) {
            msg = msg+".";
        }
        this.statusCode = statusCode;
        this.errorMessage = msg;
    }

    public int getStatusCode() {
        return statusCode;
    }

    public String getErrorMessage() {
        return errorMessage;
    }

    public void setErrorCode(int statusCode) {
        this.statusCode = statusCode;
    }

    @Override
    public Throwable fillInStackTrace() {
        return this;
    }

}